//
//  WizzardViewController.m
//  
//
//  Created by sungeo on 15/8/26.
//
//

#import "WizzardViewController.h"
#import "WMAppSetting.h"
#import "DataManager.h"
#import <NSObject+GLPubSub.h>
#import <EXTScope.h>

@implementation WizzardViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    
    @weakify(self);
    [self subscribe:WMGotSettingFromiCloud handler:^(GLEvent * event) {
        @strongify(self);
        
        if (self.editMode == NO) {
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView * av = [[UIAlertView alloc] initWithTitle:@"数据同步成功！" message:@"已经从 iCloud 同步数据到您的设备，按下确定后直接进入应用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [av show];
            });
        }
        
    }];
}

#pragma mark - alert view delegate
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (buttonIndex == alertView.cancelButtonIndex) {
        @weakify(self);
        dispatch_async(dispatch_get_main_queue(), ^{
            // 退出向导界面
            [[DataManager defaultInstance] setAppSetFinished];
            
            @strongify(self);
            [self dismissViewControllerAnimated:YES completion:nil];
        });
    }
}

@end
